//set main namespace
goog.provide('counter');
 

//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.RoundedRect');
goog.require('lime.Sprite');
goog.require('lime.fill.Frame');
goog.require('lime.animation.MoveTo');
goog.require('lime.animation.KeyframeAnimation');
goog.require('lime.animation.MoveBy');
goog.require('lime.SpriteSheet');
goog.require('lime.animation.Loop');
goog.require('lime.animation.Sequence');
// entrypoint
counter.start = function(){
    background =  new lime.fill.Image('img/bg.jpg').setSize(730,600).setOffset(0,0,false);

    nums = [];
    nums[0] = new lime.fill.Image('img/lvl_0.png').setSize(35,36).setOffset(0,0,false);
    nums[1] = new lime.fill.Image('img/lvl_1.png').setSize(35,36).setOffset(0,10,false);
    nums[2] = new lime.fill.Image('img/lvl_2.png').setSize(35,36).setOffset(0,0,false);
    nums[3] = new lime.fill.Image('img/lvl_3.png').setSize(35,36).setOffset(0,10,false);
    nums[4] = new lime.fill.Image('img/lvl_4.png').setSize(35,36).setOffset(0,0,false);
    nums[5] = new lime.fill.Image('img/lvl_5.png').setSize(35,36).setOffset(0,0,false);
    nums[6] = new lime.fill.Image('img/lvl_6.png').setSize(35,36).setOffset(0,10,false);
    nums[7] = new lime.fill.Image('img/lvl_7.png').setSize(35,36).setOffset(0,10,false);
    nums[8] = new lime.fill.Image('img/lvl_8.png').setSize(35,36).setOffset(0,10,false);
    nums[9] = new lime.fill.Image('img/lvl_9.png').setSize(35,36).setOffset(0,10,false);


	var director = new lime.Director(document.getElementById("c_wrap"),730,600),
	    scene = new lime.Scene(),
        counter_ = new lime.Layer().setPosition(200,280),
        bg_ = new lime.RoundedRect().setPosition(365,300).setStroke(1,'#c00'),


        box = new lime.RoundedRect().setRadius(20).setSize(40,50).setPosition(0,0).setStroke(1,'#c00'),
        box2 = new lime.RoundedRect().setRadius(20).setSize(40,50).setPosition(20,0).setStroke(1,'#c00'),
        box3 = new lime.RoundedRect().setRadius(20).setSize(40,50).setPosition(40,0).setStroke(1,'#c00')
            ;
//        sprite2 = new lime.RoundedRect().setRadius(20).setSize(30,30).setPosition(0,0).setStroke(1,'#c00'),
//        sprite1 = new lime.RoundedRect().setRadius(20).setSize(30,30).setPosition(20,0).setStroke(1,'#c00'),
//        sprite0 = new lime.RoundedRect().setRadius(20).setSize(30,30).setPosition(40,0).setStroke(1,'#c00');
//
//    var anim0 = new lime.animation.KeyframeAnimation().setDelay(1).
//        addFrame(nums[0]).addFrame(nums[1]).addFrame(nums[2]).addFrame(nums[3]).addFrame(nums[4]).addFrame(nums[5]).
//        addFrame(nums[6]).addFrame(nums[7]).addFrame(nums[8]).addFrame(nums[9]);
//
//    var anim1 = new lime.animation.KeyframeAnimation().setDelay(10).
//        addFrame(nums[0]).addFrame(nums[1]).addFrame(nums[2]).addFrame(nums[3]).addFrame(nums[4]).addFrame(nums[5]).
//        addFrame(nums[6]).addFrame(nums[7]).addFrame(nums[8]).addFrame(nums[9]);
//
//    var anim2 = new lime.animation.KeyframeAnimation().setDelay(100).
//        addFrame(nums[0]).addFrame(nums[1]).addFrame(nums[2]).addFrame(nums[3]).addFrame(nums[4]).addFrame(nums[5]).
//        addFrame(nums[6]).addFrame(nums[7]).addFrame(nums[8]).addFrame(nums[9])
    var frame = new lime.fill.Frame('img/num_sprite.png', 0, 0, 40, 50); //x , y, width, height
    var frame2 = new lime.fill.Frame('img/num_sprite.png', 0, 0, 40, 50); //x , y, width, height
    var frame3 = new lime.fill.Frame('img/num_sprite.png', 0, 0, 40, 50); //x , y, width, height
    box.setFill(frame);
    box2.setFill(frame2);
    box3.setFill(frame3);

    var anim = new lime.animation.KeyframeAnimation();
    anim.delay = 0.5;
    for (var i = 0; i < 10; i++) {
        anim.addFrame(new lime.fill.Frame('img/num_sprite.png', 0, 40 * i, 40, 50));
    }
    var anim2 = new lime.animation.KeyframeAnimation();
    anim2.delay = 2.5;
    for (var j = 0; j < 10; j++) {
        anim2.addFrame(new lime.fill.Frame('img/num_sprite.png', 0, 40 * j, 40, 50));
    }
    var anim3 = new lime.animation.KeyframeAnimation();
    anim3.delay = 50;
    for (var k = 0; k < 10; k++) {
        anim3.addFrame(new lime.fill.Frame('img/num_sprite.png', 0, 40 * k, 40, 50));
    }
    var moveRight = new lime.animation.MoveTo(0, 0)
        .setSpeed(1)
        .setEasing(lime.animation.Easing.LINEAR);

    var moveLeft = new lime.animation.MoveTo(0, 10)
        .setSpeed(1)
        .setEasing(lime.animation.Easing.LINEAR);

    scene.runAction(new lime.animation.Loop(
        new lime.animation.Sequence(moveLeft, moveRight)

    ));
    box.runAction(anim);
    box2.runAction(anim2);
    box3.runAction(anim3);
//
//    //scene.setFill(frame);
//    sprite0.runAction(anim0);
//    sprite1.runAction(anim1);
//    sprite2.runAction(anim2);
//
        bg_.appendChild(box);
        bg_.appendChild(box2);
        bg_.appendChild(box3);
//    bg_.appendChild(sprite0);
//    bg_.appendChild(sprite1);
//    bg_.appendChild(sprite2);
        bg_.setFill('img/bg.jpg');
//    scene.appendChild(counter_);
    scene.appendChild(bg_);
	director.replaceScene(scene);

}


//this is required for outside access after code is compiled in ADVANCED_COMPILATIONS mode
goog.exportSymbol('counter.start', counter.start);
